'''
    自动存取款机系统
    1.账户数据源
    2.登陆检验功能
    3.查询余额
    4.取钱
    5.存钱
    6.退出系统
    7.界面和交互
'''

# 1.账户数据源
account_list = [
    {'account':'user1', 'password':'123456', 'money':1000},
    {'account':'user2', 'password':'987654', 'money':1000},
    {'account':'user3', 'password':'666666', 'money':1000}]

# 2.登陆检验功能
def loginCheck(user, password):
    for id, account_dict in enumerate(account_list):
        if user == account_dict['account'] and password == account_dict['password']:
            return id
    return -1

# 3.查询余额
def showMoney(id):
    print('当前余额：', account_list[id]['money'])

# 4.取钱
def getMoney(id, money):
    account_money = account_list[id]['money']
    if money > account_money:
        print('取款金额输入错误，请重新输入')
        return -1
    else:
        account_money = account_money - money
        print('取钱完毕')
    return account_money

# 5.存钱
def saveMoney(id, money):
    account_money = account_list[id]['money']
    account_money = account_money + money
    print('存钱完毕')
    return account_money

# 6.退出系统
def loginOut():
    pass

# 7.界面和交互
while True:
    result = False
    # 登陆
    while True:
        print('登陆：')
        user = input('用户名：')
        password = input('密码：')
        id = loginCheck(user, password)
        if id < 0:
            print('密码输入错误，请重新登陆')
        else:
            break

    while True:
        # 初始界面
        print('=' * 12, 'ATM存取款系统', '=' * 12)
        print('{:1} {:<13} {:<15}'.format(' ', '1. 查询余额', '2. 取款'))
        print('{:1} {:<14} {:<15}'.format(' ', '3. 存款', '4. 退出系统'))
        print('=' * 40)
        key = input('请输入对应的选择：')
        # 根据输入操作值，执行对应操作
        if key == '1':
            showMoney(id)
            input('按回车继续')
        elif key == '2':
            while True:
                money = input('请输入取款金额：')
                money = getMoney(id, int(money))
                if money > 0:
                    account_list[id]['money'] = money
                    break
        elif key == '3':
            money = input('请输入存款金额：')
            account_list[id]['money'] = saveMoney(id, int(money))
        elif key == '4':
            loginOut()
            print('=' * 12, '再见', '=' * 12)
            result = True
            break
        else:
            print('=' * 12, '操作无效', '=' * 12)

    if result == True:
        break